from django.contrib.auth.models import User
from django.db import models


# Create your models here.

class Folder(models.Model):
    name = models.CharField(max_length=255, verbose_name='名称')
    user = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='创建者')
    parent_folder = models.ForeignKey('self', null=True, blank=True,
                                      on_delete=models.CASCADE, verbose_name='父文件夹')

    class Meta:
        verbose_name = '文件夹'
        verbose_name_plural = '文件夹管理'

    def __str__(self):
        return self.name


class File(models.Model):
    name = models.CharField(max_length=255, verbose_name='名称')
    file = models.FileField(upload_to='uploads/', verbose_name='文件对象')
    folder = models.ForeignKey(Folder, on_delete=models.CASCADE, verbose_name='文件夹')
    uploaded_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='上传者')
    # shared_with = models.ManyToManyField(User, related_name='shared_files', verbose_name='分享给...')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')

    class Meta:
        verbose_name = '文件'
        verbose_name_plural = '文件管理'

    def __str__(self):
        return self.name
